package com.gotop.mapper.core.log.publisher;

import com.gotop.common.utils.ApplicationStringUtils;
import com.gotop.common.utils.WebUtil;
import com.gotop.entity.log.LogUsual;
import com.gotop.mapper.core.log.event.UsualLogEvent;
import com.gotop.mapper.core.log.util.LogAbstractUtil;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

/**
 * @program: cem
 * @description:
 * @author: superfish
 * @create: 2020-12-28 15:10
 **/
public class UsualLogPublisher {
    public UsualLogPublisher() {
    }

    public static void publishEvent(String level, String id, String data) {
        HttpServletRequest request = WebUtil.getRequest();
        LogUsual logUsual = new LogUsual();
        logUsual.setLogLevel(level);
        logUsual.setLogId(id);
        logUsual.setLogData(data);
        LogAbstractUtil.addRequestInfoToLog(request, logUsual);
        Map<String, Object> event = new HashMap(16);
        event.put("log", logUsual);
        event.put("request", request);
        ApplicationStringUtils.publishEvent(new UsualLogEvent(event));
    }
}
